<?php
/**
 *   Kaltura Browser - administrator/components/com_kaltura/views/fieldservices/view.html.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2011 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');
jimport('joomla.utilities.simplexml');

class KalturaViewFieldservices extends JView {
    function display() {
        $model = $this->getModel('fields');
        
        $model->setId(JRequest::getVar('id'));
        $field = $model->getField();
        
        $xml = new JSimpleXMLElement('field', array(
            'id' => $field->id,
            'key' => $field->field_name,
            'label' => $field->field_label,
            'type' => $field->field_type,
            'visible' => $field->field_visible
        ));
        
        if ($field->field_type == KalturaModelFields::FIELD_TYPE_LIST) {
            $items = $model->getFieldItems(JRequest::getVar('id'));
            foreach ($items as $it) {
                $child =& $xml->addChild('item', array('id' => $it->id));
                $child->setData($it->field_value);
            }
        }
        
        $document =& JFactory::getDocument();
        $document->setMimeEncoding('text/xml');
        
        echo '<?xml version="1.0" encoding="UTF-8" ?>'."\n";
        echo $xml->toString();
        
    }
}
